package com.example.night.controller;

import com.example.night.data.EsSummary.EsSummaryPackage;
import com.example.night.service.ApiService.EsSummaryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/summary")
public class EsSummaryController {

    private final EsSummaryService esSummaryService;

    // 构造函数注入 EsSummaryService
    public EsSummaryController(EsSummaryService esSummaryService) {
        this.esSummaryService = esSummaryService;
    }

    @GetMapping("/get_order_summary")
    public EsSummaryPackage getOrderSummaryData(
            @RequestParam String start_time,
            @RequestParam String end_time,
            @RequestParam String title,
            @RequestParam int status,
            @RequestParam int extend_type,
            @RequestParam String promoterId
    ) {

        if (extend_type == 1) {
            extend_type = 2;
        } else if (extend_type == 2) {
            extend_type = 1;
        }

        EsSummaryPackage summary = esSummaryService.getEsSummaryData(start_time, end_time, title, status, extend_type, promoterId);

//        if (summary == null) {
//            return Map.of("error", "获取订单汇总失败");
//        }

        return summary;
    }
}
